import { defineStore } from 'pinia'

//引入接口
import { reqLogin } from '@/api/user'
//引入数据类型
import type { loginForm, loginResponseData } from '@/api/user/type'
import {SET_TOKEN,GET_TOKEN} from '@/utils/token'
import type { UserState } from './types/type'
let useUserStore = defineStore('User', {
    state: () :UserState=> {
        return {
            token:GET_TOKEN(),
        }
    },
    actions: {
        //用户登录
        async userLogin(data: loginForm) {
            let result:loginResponseData = await reqLogin(data);
            if(result.code==200){
                this.token = (result.data.token as string);
                SET_TOKEN(result.data.token as string);
                return 'ok';
            }else{
                return Promise.reject(new Error(result.data.message))
            }
        }
    },
    getters: {

    }
})

export default useUserStore;